package com.example.springboot.globalutils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.List;

@NoArgsConstructor
//@ApiModel("分页结果包装体")
public class Paged<T> {
//    @ApiModelProperty("当前页码")
    private Long pageNum;
//    @ApiModelProperty("每页显示的数量")
    private Long pageSize;
//    @ApiModelProperty("总数据条数")
    private Long total;
//    @ApiModelProperty("分页数据")
    private List<T> list;

    Paged(final long pageNum, final long pageSize, final long total, final List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
    }

    public static <T> Paged<T> wrapEmpty(final Integer pageNum, final Integer pageSize) {
        return new Paged<>(1, 10, 0, Collections.emptyList());
    }

    public static <T> Paged<T> wrap(final IPage<T> paged) {
        return new Paged<>(paged.getCurrent(), paged.getSize(), paged.getTotal(), paged.getRecords());
    }

    public static <T> Paged<T> wrap(final IPage paged, final List<T> list) {
        return new Paged<>(paged.getCurrent(), paged.getSize(), paged.getTotal(), list);
    }

    public static <T> Paged<T> wrap(final Page<T> paged) {
        return new Paged<>(paged.getPageNum(), paged.getPageSize(), paged.getTotal(), paged.getResult());
    }

    public static <T> Paged<T> wrap(final Page paged, final List<T> list) {
        return new Paged<>(paged.getPageNum(), paged.getPageSize(), paged.getTotal(), list);
    }

    public static <T> Paged<T> wrap(final PageInfo<T> paged) {
        return new Paged<>(paged.getPageNum(), paged.getPageSize(), paged.getTotal(), paged.getList());
    }

    public static <T> Paged<T> wrap(final PageInfo paged, final List<T> list) {
        return new Paged<>(paged.getPageNum(), paged.getPageSize(), paged.getTotal(), list);
    }

    public static <T> Paged<T> wrap(final long pageNum, final long pageSize, final long total, final List<T> list) {
        return new Paged<>(pageNum, pageSize, total, list);
    }

    public Long getPageNum() {
        return pageNum;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public Long getTotal() {
        return total;
    }

    public List<T> getList() {
        return list;
    }
}
